package com.dsx.commons.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
//后端传给前端的对象，是否正常传送，信息，数据
public class Result implements Serializable {
    private int code;//200表示正常，其余是异常
    private String msg;
    private Object data;
    
    
    public static Result success(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static Result success(String msg,Object data){
        Result r = new Result();
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static Result success(Object data){
        Result r = new Result();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(data);
        return r;
    }
    public static Result fail(int code,String msg,Object data){
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static Result fail(String msg,Object data){
        Result r = new Result();
        r.setCode(300);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static Result fail(String msg){
        Result r = new Result();
        r.setCode(300);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }
    
}
